package com.itheima.a_cookie;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RulesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//创建cookie
		Cookie cookie1 = new Cookie("bkey", "bvalue");
		Cookie cookie2 = new Cookie("ckey", "cvalue");
		Cookie cookie3 = new Cookie("dkey", "dvalue");
		Cookie cookie4 = new Cookie("dkey", "ssss");
		
		//设置路径
		cookie3.setPath(request.getContextPath()+"/aa/bb");
		cookie4.setPath(request.getContextPath()+"/aa/bb/cc");
		
		//写回浏览器
		response.addCookie(cookie1);
		response.addCookie(cookie2);
		response.addCookie(cookie3);
		response.addCookie(cookie4);
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}